package horizon.collision;

import horizon.component.CollisionComponent;
import horizon.component.IRenderUpdate;
import horizon.entity.Entity;
import horizon.graphics.RenderingContext;
import horizon.map.Map;
import horizon.map.Tile;
import horizon.util.Vector2;
import java.util.HashMap;
import java.util.Iterator;

public class CollisionManager implements IRenderUpdate {

    HashMap<String, Entity> entities = new HashMap<>();

    /*
     * TODO: Write new collision manager
     */
    public CollisionManager(Map m) {
    }

    public void doCollisions() {
    }

    public void addEntity(Entity e) {

        
        CollisionComponent col = ((CollisionComponent) e.getComponent(CollisionComponent.class));
        
        if(col != null)
            col.setCollisionManager(this);


        if (!(e instanceof Tile)) {

            entities.put(e.getId(), e);

        }
    }

    public Entity getEntity(String id) {

        return entities.get(id);

    }

    public void removeEntity(String id) {


        entities.remove(id);

    }

    @Override
    public void update(long elapsedTime) {

        Iterator<Entity> it = entities.values().iterator();

        while (it.hasNext()) {

            Entity e = it.next();
            e.update(elapsedTime);

        }

    }

    @Override
    public void render(RenderingContext r) {

        Iterator<Entity> it = entities.values().iterator();

        while (it.hasNext()) {

            Entity e = it.next();
            e.render(r);

        }

    }

    public HashMap<String, Entity> getEntities() {
        return entities;
    }
}
